Convert Letters to Numbers in Python

71

Convert Letters to Numbers in Python -

Convert Letters to Numbers in Python using ord() method
text= "itsmycode"
num_list = []

# iterate each characters in string
# and convert to number using ord()
for c in text:
   num_list.append(ord(c) - 96)

# print the converted letters as numbers in list
print("After converting letters to numbers",num_list)

Comments

Submit
0 Comments